/*
 * Copyright (C) 2020, 2019, 2018, 2017 Girish M
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 */
 #include <stdio.h>
#include <malloc.h>

int main(void)
{
 unsigned int m, n, i, j, k=1;
 int* a;
 printf("\nEnter the size of matrix:\n");
 printf("\nNo. of rows:\n");
 scanf("%u", &m);
 printf("\nNo. of cols:\n");
 scanf("%u", &n);
 a = (int*) malloc(sizeof(int)*m*n);
 if(NULL != a)
 {
   for(i=0; i<m; i++)
  {
   for(j=0; j<n; j++)
   {
     printf("\nEnter element a[%d][%d]: \n", i+1, j+1);
     printf("\nloc: %d\n", i+j+k);
     scanf("%d", &a[i+j+k]);
   }
   k=k+n-1;
  }
  printf("\nEntered array:\n");
  k=1;
  for(i=0; i<m; i++)
  {
   for(j=0; j<n; j++)
   {
     printf("%d ", a[i+j+k]);
   }
   printf("\n");
   k=k+n-1;
  }
  free(a);
 }
 return 0;
}
